package com.wsg.lightaccounting.Adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.TextView;

import com.wsg.lightaccounting.Model.Account;
import com.wsg.lightaccounting.Model.AccountManager;
import com.wsg.lightaccounting.Model.CashCard;
import com.wsg.lightaccounting.Model.CreditCard;
import com.wsg.lightaccounting.Model.Customized;
import com.wsg.lightaccounting.Model.NetworkPayment;
import com.wsg.lightaccounting.R;

import java.util.List;

/**
 * Created by dell-pc on 2016/11/21.
 */

public class IconAccountAdapter extends BaseAdapter{
    private Context context;
    private List<Account> accounts;
    public IconAccountAdapter(Context context) {
        this.context = context;
        accounts = AccountManager.accounts;
    }
    @Override
    public int getCount() {
        return accounts.size();
    }

    @Override
    public Object getItem(int position) {
        return accounts.get(position);
    }

    @Override
    public long getItemId(int position) {
        return accounts.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        Item item ;
        LayoutInflater inflater =  LayoutInflater.from(context);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.wallet_layout, null);
            item = new Item((TextView) convertView.findViewById(R.id.wallet_balance),(TextView)convertView.findViewById(R.id.wallet_name),
                    (TextView)convertView.findViewById(R.id.wallet_information) ,(ImageView)convertView.findViewById(R.id.wallet_icon));
            convertView.setTag(item);
        }
        else{
            item =(Item) convertView.getTag();
        }
        Account account = accounts.get(position);
        AccountManager.setAccountColor(context,convertView,accounts.get(position).getColor());
        AccountManager.setAccountInformation(item.name,item.information,account);
        item.balance.setText(String.valueOf(account.getBalance()));
        AccountManager.setAccountIcon(item.icon,account.getType());
        return convertView;
    }
    class Item{
        protected TextView balance,name,information;
        protected ImageView icon;
        public Item(TextView balance, TextView name, TextView information, ImageView icon) {
            this.balance = balance;
            this.name = name;
            this.information = information;
            this.icon = icon;
        }
    }


}
